﻿/****************************** Module Header ******************************\

Copyright (c) Gary Davidson

This source is subject to the Microsoft Public License.
See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
All other rights reserved.

THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/

using System;
using System.Xml.Linq;

namespace Savviety.ServiceManager.API.Criteria
{

    public class SimpleExpression : Expression
    {
        private readonly string _property;
        private readonly string _value;
        private readonly ExpressionOperator _expressionOperator;

        public SimpleExpression(string property, string value, ExpressionOperator expressionOperator)
        {
            this._property = property;
            this._value = value;
            this._expressionOperator = expressionOperator;
        }

        public override XElement ToXElement()
        {

            Root = GetXElement("Expression");
          
         
            var el1 = GetXElement("SimpleExpression");
            Root.Add(el1);

            var leftElement = GetLeftExpression(_property);
            el1.Add(leftElement);
            var operatorElement = GetXElement("Operator", Enum.GetName(typeof(ExpressionOperator), _expressionOperator));
            el1.Add(operatorElement);
            var rightElement = GetRightExpression(_value);
            el1.Add(rightElement);

            return Root;

        }

    }
}